"""Definition of the classinfo content type
"""

from zope.interface import implements

from Products.Archetypes import atapi
from Products.ATContentTypes.content import base
from Products.ATContentTypes.content import schemata

# -*- Message Factory Imported Here -*-
from my315ok.xtinfocontent import xtinfocontentMessageFactory as _

from my315ok.xtinfocontent.interfaces import Iclassinfo
from my315ok.xtinfocontent.config import PROJECTNAME

classinfoSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((
                                                                      
    atapi.StringField(
        'infocode',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"info code"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'category',
        storage=atapi.AnnotationStorage(),
        vocabulary_factory=u"my315ok.xtinfocontent.classinfocategory",
        enforceVocabulary=True,
        widget=atapi.SelectionWidget(
            label=_(u"category"),
            description=_(u""),            
        ),
    ),


    atapi.StringField(
        'subject',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"subject"),
            description=_(u"subject"),
        ),
    ),


    atapi.TextField(
        'text',
        searchable=True,
        storage=atapi.AnnotationStorage(),
        widget=atapi.RichWidget(
            label=_(u"detail description"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'status',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"status"),
            description=_(u""),
        ),
    ),


    atapi.FixedPointField(
        'price',
        storage=atapi.AnnotationStorage(),
        widget=atapi.DecimalWidget(
            label=_(u"refer price"),
            description=_(u""),
        ),
        validators=('isDecimal'),
    ),


    atapi.StringField(
        'name',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"contact person"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'addr',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"address"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'phone',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"phone number"),
            description=_(u""),
        ),
        required=True,
    ),


    atapi.IntegerField(
        'qq',
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"QQ number"),
            description=_(u""),
        ),
        validators=('isInt'),
    ),


    atapi.StringField(
        'author',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"author"),
            description=_(u""),
        ),
    ),


))

# Set storage on fields copied from ATContentTypeSchema, making sure
# they work well with the python bridge properties.

classinfoSchema['title'].storage = atapi.AnnotationStorage()
classinfoSchema['description'].storage = atapi.AnnotationStorage()

schemata.finalizeATCTSchema(classinfoSchema, moveDiscussion=False)


class classinfo(base.ATCTContent):
    """a class information type"""
    implements(Iclassinfo)

    meta_type = "classinfo"
    schema = classinfoSchema
    _at_rename_after_creation = True

    title = atapi.ATFieldProperty('title')
    description = atapi.ATFieldProperty('description')

    # -*- Your ATSchema to Python Property Bridges Here ... -*-
    infocode = atapi.ATFieldProperty('infocode')

    category = atapi.ATFieldProperty('category')

    subject = atapi.ATFieldProperty('subject')

    text = atapi.ATFieldProperty('text')

    status = atapi.ATFieldProperty('status')

    price = atapi.ATFieldProperty('price')

    name = atapi.ATFieldProperty('name')

    addr = atapi.ATFieldProperty('addr')

    phone = atapi.ATFieldProperty('phone')

    qq = atapi.ATFieldProperty('qq')

    author = atapi.ATFieldProperty('author')


atapi.registerType(classinfo, PROJECTNAME)
